/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Trp_colegioDAOImpl implements orm.dao.Trp_colegioDAO {
	public Trp_colegio loadTrp_colegioByORMID(String co_id) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_colegioByORMID(session, co_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_colegio getTrp_colegioByORMID(String co_id) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return getTrp_colegioByORMID(session, co_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_colegio loadTrp_colegioByORMID(String co_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_colegioByORMID(session, co_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_colegio getTrp_colegioByORMID(String co_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return getTrp_colegioByORMID(session, co_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_colegio loadTrp_colegioByORMID(PersistentSession session, String co_id) throws PersistentException {
		try {
			return (Trp_colegio) session.load(orm.Trp_colegio.class, co_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_colegio getTrp_colegioByORMID(PersistentSession session, String co_id) throws PersistentException {
		try {
			return (Trp_colegio) session.get(orm.Trp_colegio.class, co_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_colegio loadTrp_colegioByORMID(PersistentSession session, String co_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Trp_colegio) session.load(orm.Trp_colegio.class, co_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_colegio getTrp_colegioByORMID(PersistentSession session, String co_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Trp_colegio) session.get(orm.Trp_colegio.class, co_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_colegio[] listTrp_colegioByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return listTrp_colegioByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_colegio[] listTrp_colegioByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return listTrp_colegioByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_colegio[] listTrp_colegioByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_colegio as Trp_colegio");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Trp_colegio[]) list.toArray(new Trp_colegio[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_colegio[] listTrp_colegioByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_colegio as Trp_colegio");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Trp_colegio[]) list.toArray(new Trp_colegio[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_colegio loadTrp_colegioByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_colegioByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_colegio loadTrp_colegioByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_colegioByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_colegio loadTrp_colegioByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Trp_colegio[] trp_colegios = listTrp_colegioByQuery(session, condition, orderBy);
		if (trp_colegios != null && trp_colegios.length > 0)
			return trp_colegios[0];
		else
			return null;
	}
	
	public Trp_colegio loadTrp_colegioByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Trp_colegio[] trp_colegios = listTrp_colegioByQuery(session, condition, orderBy, lockMode);
		if (trp_colegios != null && trp_colegios.length > 0)
			return trp_colegios[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTrp_colegioByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return iterateTrp_colegioByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_colegioByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return iterateTrp_colegioByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_colegioByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_colegio as Trp_colegio");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_colegioByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_colegio as Trp_colegio");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_colegio createTrp_colegio() {
		return new orm.Trp_colegio();
	}
	
	public boolean save(orm.Trp_colegio trp_colegio) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().saveObject(trp_colegio);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Trp_colegio trp_colegio) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().deleteObject(trp_colegio);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Trp_colegio trp_colegio)throws PersistentException {
		try {
			if(trp_colegio.getTipo_coleg() != null) {
				trp_colegio.getTipo_coleg().trp_colegio.remove(trp_colegio);
			}
			
			if(trp_colegio.getSocio_eco() != null) {
				trp_colegio.getSocio_eco().trp_colegio.remove(trp_colegio);
			}
			
			if(trp_colegio.getProvincia() != null) {
				trp_colegio.getProvincia().trp_colegio.remove(trp_colegio);
			}
			
			orm.Trp_curso[] lTrp_cursos = trp_colegio.trp_curso.toArray();
			for(int i = 0; i < lTrp_cursos.length; i++) {
				lTrp_cursos[i].setColegio(null);
			}
			return delete(trp_colegio);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Trp_colegio trp_colegio, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(trp_colegio.getTipo_coleg() != null) {
				trp_colegio.getTipo_coleg().trp_colegio.remove(trp_colegio);
			}
			
			if(trp_colegio.getSocio_eco() != null) {
				trp_colegio.getSocio_eco().trp_colegio.remove(trp_colegio);
			}
			
			if(trp_colegio.getProvincia() != null) {
				trp_colegio.getProvincia().trp_colegio.remove(trp_colegio);
			}
			
			orm.Trp_curso[] lTrp_cursos = trp_colegio.trp_curso.toArray();
			for(int i = 0; i < lTrp_cursos.length; i++) {
				lTrp_cursos[i].setColegio(null);
			}
			try {
				session.delete(trp_colegio);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Trp_colegio trp_colegio) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().getSession().refresh(trp_colegio);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Trp_colegio trp_colegio) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().getSession().evict(trp_colegio);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_colegio loadTrp_colegioByCriteria(Trp_colegioCriteria trp_colegioCriteria) {
		Trp_colegio[] trp_colegios = listTrp_colegioByCriteria(trp_colegioCriteria);
		if(trp_colegios == null || trp_colegios.length == 0) {
			return null;
		}
		return trp_colegios[0];
	}
	
	public Trp_colegio[] listTrp_colegioByCriteria(Trp_colegioCriteria trp_colegioCriteria) {
		return trp_colegioCriteria.listTrp_colegio();
	}
}
